package com.lam.smartbutlerv4.ui;
/*
 *  project name:       SmartButlerV5
 *  pakcage name:       com.lam.smartbutlerv4.ui
 *  file name:          ColesCLD1
 *  create date:        2019/2/17 21:20
 *  creator:            Luan Xiyuan
 *  description:        TODO
 */

import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.lam.smartbutlerv4.R;
import com.lam.smartbutlerv4.service.card.CardFragmentPagerAdapter;
import com.lam.smartbutlerv4.service.card.CardItem;
import com.lam.smartbutlerv4.service.card.CardPagerAdapter;
import com.lam.smartbutlerv4.service.card.ShadowTransformer;

public class ColesCard extends AppCompatActivity {

//    private Button mButton;
    private ViewPager mViewPager;

    private CardPagerAdapter mCardAdapter;
    private ShadowTransformer mCardShadowTransformer;
    private CardFragmentPagerAdapter mFragmentCardAdapter;
    private ShadowTransformer mFragmentCardShadowTransformer;

    private boolean mShowingFragments = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coles_card);
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
//        mButton = (Button) findViewById(R.id.cardTypeBtn);
//        ((CheckBox) findViewById(R.id.checkBox)).setOnCheckedChangeListener(this);
//        mButton.setOnClickListener(this);

        mCardAdapter = new CardPagerAdapter();
        mCardAdapter.addCardItem(new CardItem(R.string.title_11, R.string.text_1, R.drawable.card1, R.string.cardnumber_1, R.string.current_creditlimit_1));
        mCardAdapter.addCardItem(new CardItem(R.string.title_21, R.string.text_1, R.drawable.card2, R.string.cardnumber_2, R.string.current_creditlimit_2));
        mCardAdapter.addCardItem(new CardItem(R.string.title_31, R.string.text_1, R.drawable.card3, R.string.cardnumber_3, R.string.current_creditlimit_3));
        mCardAdapter.addCardItem(new CardItem(R.string.title_41, R.string.text_1, R.drawable.card4, R.string.cardnumber_4, R.string.current_creditlimit_4));
        mFragmentCardAdapter = new CardFragmentPagerAdapter(getSupportFragmentManager(),
                dpToPixels(2, this));

        mCardShadowTransformer = new ShadowTransformer(mViewPager, mCardAdapter);
        mFragmentCardShadowTransformer = new ShadowTransformer(mViewPager, mFragmentCardAdapter);
        mCardShadowTransformer.enableScaling(true);
        mFragmentCardShadowTransformer.enableScaling(true);

        mViewPager.setAdapter(mCardAdapter);
        mViewPager.setPageTransformer(false, mCardShadowTransformer);
        mViewPager.setOffscreenPageLimit(3);
    }

//    @Override
//    public void onClick(View view) {
//        if (!mShowingFragments) {
//            mButton.setText("Views");
//            mViewPager.setAdapter(mFragmentCardAdapter);
//            mViewPager.setPageTransformer(false, mFragmentCardShadowTransformer);
//        } else {
//            mButton.setText("Fragments");
//            mViewPager.setAdapter(mCardAdapter);
//            mViewPager.setPageTransformer(false, mCardShadowTransformer);
//        }
//
//        mShowingFragments = !mShowingFragments;
//    }

    public static float dpToPixels(int dp, Context context) {
        return dp * (context.getResources().getDisplayMetrics().density);
    }

//    @Override
//    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
//        mCardShadowTransformer.enableScaling(b);
//        mFragmentCardShadowTransformer.enableScaling(b);
//    }
}
